package com.hkbigdata.springbootdemo.controller;

import com.hkbigdata.springbootdemo.bean.Employee;
import com.hkbigdata.springbootdemo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liuanbo
 * @creat 2024-11-08-11:16
 * @see 2194550857@qq.com
 */
@RestController
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;


    @GetMapping("/getAllEmp")
    public List<Employee> getAllEmp() {
        return employeeService.findAll();
    }

    @GetMapping("/emp")
    public Object getEmp(String op, Integer id, String lastname, String gender, String email) {
        //封装对象
        Employee employee = new Employee(id, lastname, gender, email);
        switch (op) {

            case "select":
                if (id == null) {
                    return "必须传入员工id！";
                } else {
                    Employee e = employeeService.findById(id);
                    return e == null ? "查无此人!" : e;
                }

            case "insert":
                employeeService.add(employee);
                return "操作完成!";

            case "update":
                if (id == null) {
                    return "必须传入员工id！";
                } else {
                    employeeService.update(employee);
                    return "操作完成!";
                }

            case "delete":
                if (id == null) {
                    return "必须传入员工id！";
                } else {
                    employeeService.deleteById(id);
                    return "操作完成!";
                }

            default:
                return "请正确操作";
        }
    }
}
